<?php

namespace app\api\controller;
use app\common\logic\Logic;
use app\common\logic\SkillApply;
use app\common\model\OrderRecord;
use app\common\model\SkillApply as apply;
use app\common\model\Order;
use app\common\model\Skill as model;
use GatewayWorker\Lib\Gateway;
use think\Db;
use think\Exception;

class Skill extends User
{

    /**
     * 技能类型列表
     */
    public function skill()
    {
        $model = new model();

        $skill_ids = [];
        $data['my']   = (new apply())->getMy(['u.user_id' => $this->user_id, 'a.status' => 1]);
        $data['my'] && $skill_ids = array_column($data['my'],'skill_id');

        $data['game'] = $model->getSkillRows(['type'=>2,'status' => 1], $skill_ids, $this->user_id);
        $data['fun']  = $model->getSkillRows(['type'=>1,'status' => 1], $skill_ids, $this->user_id);

        api_return(1,'获取成功',$data);
    }




    public function mySkills()
    {
        $rows = (new apply())->getMy(['u.user_id' => $this->user_id, 'a.status' => 1]);

        api_return(1,'获取成功',$rows);
    }

    /**
     * 技能详情
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function detail()
    {

        $id = input('post.id');

        if (!is_numeric($id)) api_return(0,'参数错误');

        $map['skill_id'] = $id;

        $data['skill'] = model::with('skillForm')
            ->where($map)
            ->field('skill_id,request,skill_name,skill_img')
            ->cache(30)
            ->find();
        if (!$data['skill']) api_return(0,'非法参数');

        $map['user_id'] = $this->user_id;

        $data['my'] = Db::name('skill_apply')->where($map)->field('img,explain,status,skill_form_id')->find();

        //$data['header_img'] = $this->userInfo('header_img');

        api_return(1,'获取成功',$data);
    }

    /**
     * 申请技能
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function apply()
    {
        $this->ApiLimit(2,$this->user_id);

        $data = request()->only(['skill_id','img','explain','skill_form_id'],'post');

        $where['skill_id'] = $data['skill_id'];
        $where['status']   = 1;

        $skill = Db::name('skill')->where($where)->value('skill_id');

        if (!$skill) api_return(0,'禁止申请');

        $map['skill_id'] = $data['skill_id'];
        $map['user_id']  = $this->user_id;

        $model = new SkillApply();

        $apply = $model->where($map)->find();

        if ($apply){

            if ($apply['status'] == 0)
                api_return(0,'您的资质申请还在审核中,请勿重复操作');

            $data['id'] = $apply['apply_id'];
        }

        $data['user_id'] = $this->user_id;
        $data['status']  = 0;

        $result = $model->saveChange($data);

        if ($result){
            api_return(1,'提交成功,请等待管理员审核');
        }
        api_return(0,$model->getError());
    }


    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 资质上下架
     */
    public function shelf(int $id,int $is_use)
    {

        $map['skill_id'] = $id;
        $map['user_id']  = $this->user_id;
        $map['status']   = 1;

        $model = new SkillApply();

        $data  = $model->where($map)->find();

        if ($data){

            $result = $data->validate('base.skill_shelf')->save(['is_use'=>$is_use]);

            if ($result){

                api_return(1,'修改成功');

            }

            api_return(0,$data->getError());

        }else{

            api_return(0,'参数错误');

        }

    }

    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 资质设置--显示页
     */
    public function setSkill()
    {

        $id = input('post.id');
        if (!is_numeric($id)) api_return(0,'缺少技能id');

        $map['a.user_id']  = $this->user_id;
        $map['a.status']   = 1;
        $map['a.is_use']   = 1;
        $map['s.skill_id'] = $id;

        $model = new apply();

        $data['rows']  = $model->getRows($map);

        api_return(1,'获取成功',$data);

    }

    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 技能编辑
     */
    public function editSkill()
    {

        $data = request()->only(['my_form','my_gift_id','apply_id'],'post');

        $map['apply_id'] = $data['apply_id'];
        $map['status']   = 1;
        $map['user_id']  = $this->user_id;

        $model = new apply();

        $row = $model->where($map)->find();

        if (!$row) api_return(0,'非法参数');

        $where['skill_id'] = $row['skill_id'];

        $skill = Db::name('skill')->where($where)->find();

        $gift_ids = explode(',',$data['my_gift_id']);

        foreach ($gift_ids as $v){
            if (!strstr($skill['gift_id'],$v)) api_return(0,'礼物id错误');
        }

        $data['mini_price'] = getMiniPrice($data['my_gift_id']);

        $result = $row->update($data);

        if ($result !== false){
            api_return(1,'修改成功');
        }else{
            api_return(0,$model->getError());
        }

    }

    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 技能详情
     */
    public function skillDetail()
    {
        $id = input('post.id');

        $map['a.status']   = 1;
        $map['a.apply_id'] = $id;

        $model = new apply();

        $data  = $model->detail($map);

        $data['is_follow'] = self::isFollow($this->user_id,dehashid($data['user_id']));

        api_return(1,'获取成功',$data);

    }


    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 根据申请id   获取用户技能申请详情
     */
    protected function getApply()
    {
        $id = input('post.id');

        $map['status']   = 1;
        $map['apply_id'] = $id;

        return Db::name('skill_apply')->where($map)->cache(15)->find();
    }


    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 技能详情 -- 技能统计
     */
    public function skillCount()
    {

        $data = $this->getApply();

        $form['a.skill_id'] = $data['skill_id'];
        $form['a.user_id']  = $data['user_id'];
        $form['a.status']   = 1;
        $form['s.status']   = 1;

        $rows['forms'] = Db::name('skill_form_user')->alias('a')
            ->join('skill_form s','s.form_id = a.form_id','LEFT')
            ->where($form)
            ->order('a.num desc')
            ->field('a.num,s.form_name')
            ->cache(15)
            ->select();

        $tag['a.skill_id'] = $data['skill_id'];
        $tag['a.user_id']  = $data['user_id'];
        $tag['a.status']   = 1;
        $tag['t.status']   = 1;

        $rows['tags'] = Db::name('skill_tag_user')->alias('a')
            ->join('skill_tag t','t.tag = a.tag','LEFT')
            ->where($tag)
            ->order('a.num desc')
            ->field('a.num,t.tag_name')
            ->cache(15)
            ->select();

        $map['to_user']  = $data['user_id'];
        $map['skill_id'] = $data['skill_id'];
        $map['status']   = 5;

        $rows['count'] = self::orderCount($map);

//        $rows['count']['num'] = Db::name('order')->where($map)->count('order_id');
//
//        $score = Db::name('order')->where($map)->avg('score');
//
//        $rows['count']['score'] = numberDecimal($score);

        api_return(1,'获取成功',$rows);

    }


    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 技能详情--技能评论
     */
    public function skillComment()
    {

        $data = $this->getApply();

        $map['a.to_user']  = $data['user_id'];
        $map['a.skill_id'] = $data['skill_id'];
        $map['a.status']   = 5;

        $model = new Order();

        $rows  = $model->getComment($map);

        api_return(1,'获取成功',$rows);

    }

    /**
     * 邀约下单界面
     */
    public function invite()
    {
        $id = dehashid(input('post.id'));

        if (!is_numeric($id)) api_return(0,'参数错误');

        $rows['userInfo'] = $this->userInfo('nick_name,header_img',$id);
        $rows['userInfo']['order_num'] = $this->userExtra('order_num',$id);

        $map['a.user_id'] = $id;
        $map['a.is_use']  = 1;
        $map['a.status']  = 1;
//        $map['f.price'] = ['neq',0];
//        dd($map);
        $model = new apply();
        $rowss = [
            "skill_name" => "自定义订单",
            "skill_id"   => 0,
            "apply_id"   => 0,
            "name"       => "",
            "price"      => 0
        ];
        $rows['rows'] = $model->getRows($map,true);

        api_return(1,'获取成功',$rows);
    }

    /**
     * 下邀约单
     */
    public function order()
    {

        $this->ApiLimit(1,$this->user_id);

        $data = request()->only(['to_user','num','order_time','remark','apply_id','price'],'post');
        $to_user = dehashid($data['to_user']);

        if (!is_numeric($to_user)) api_return(0,'参数错误');

        if ($to_user == $this->user_id){
            api_return(0,'您不能向自己下单');
        }

        if($data['apply_id'])
        {
            //平台订单
            $map['status']   = 1;
            $map['user_id']  = $to_user;
            $map['is_use']   = 1;
            $map['apply_id'] = $data['apply_id'];

            $apply = apply::where($map)->find();

            if (!$apply) api_return(0,'用户无此技能');

            $data['skill_id'] = $apply['skill_id'];

            if (!isInt($data['num'])) api_return(0,'数量错误');
            $price = $apply->skillForm()->value('price');
            $data['price'] = bcmul($price,$data['num']);
        }else{
            api_return(0,'参数错误');
        }

        $data['to_user'] = $to_user;
        $data['user_id'] = $this->user_id;

        Db::startTrans();
        try{
            //钻石支付、交易记录、发消息给陪陪
            $this->moneyDec($data['price']);
            money_detail(2,$this->user_id, '支出',$data['price'],'邀约下单');

            $data['status'] = 1;
            $model = new Logic();
            $result = $model->saveChange('order',$data,'order.add');

            if (!$result){
                api_return(0,$model->getError());
            }

            Db::commit();
        }catch (Exception $e){
            Db::rollback();
            api_return(0,'服务器繁忙,请稍后重试',$e->getMessage());
        }
        $order['a.order_id'] = $model->order_id;
        $row = $this->orderDetail($order);

        $j_push_id = self::userExtra('j_push_id',$to_user);
        if ($j_push_id){
            $extra['type'] = 2;
            $extra['data'] = $row;
            $str = sprintf('接单啦！快到我的订单中心看看是谁又给您下了[%s]订单吧！',$row['skill_name']);
            j_push($str,$j_push_id,['extras'=>$extra]);
            self::sendUsrMsg('system',hashid($to_user),$str);
        }

        api_return(1,'下单成功',$row);
    }

    /**
     * 订单记录
     * type =>1 全部  type=>2 进行中 type=>3 已完成
     */
    public function receipt()
    {
        $type = input('type');

        $map = [];

        switch ($type)
        {
            case 1:
                break;
            case 2:
                $map['a.status'] = ['in','1,2'];
                break;
            case 3:
                $map['a.status'] = ['in','3,4'];
                break;
            default:
                api_return(0,'没有该类型数据');
                break;
        }

        $join = [
            [ 'skill_apply y','y.apply_id = a.apply_id','LEFT'],
            [ 'skill s','s.skill_id = y.skill_id','LEFT'],
            [ 'skill_form f','f.id = y.skill_form_id','LEFT'],
        ];
        $map['a.user_id|a.to_user'] = $this->user_id;
        $model = new Order();

        $rows = $model->getRows($this->user_id, $join,$map);

        api_return(1,'获取成功',$rows);
    }

    /**
     * 邀约详情
     */
    public function inviteDetail()
    {
        $id = input('post.id');
        if (!is_numeric($id)) api_return(0,'参数错误');
        $map['a.order_id'] = $id;

        $data = $this->orderDetail($map);

        api_return(1,'获取成功',$data);
    }

    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 订单详情
     */
    protected  function orderDetail(array $map)
    {
        $model = new Order();

        $data  = $model->getOne($map);

        if (!$data){
            api_return(0,'非法参数');
        }
        $data['order_time'] = formatTime($data['order_time']);
//        $data['order_time'] = formatTime(time()+86400);
        if ($data['user_id'] == $this->user_id){

            $data['nick_name']  = $this->userInfo('nick_name',$data['to_user']);
            $data['header_img'] = $this->userInfo('header_img',$data['to_user']);
            $data['level']      = $this->userExtra('level',$data['to_user']);
            $data['order_sum']  = $this->userExtra('order_sum',$data['to_user']);
            $data['sign']       = $this->userInfo('sign',$data['to_user']);

        }elseif($data['to_user'] == $this->user_id){

            $data['nick_name']  = $this->userInfo('nick_name',$data['user_id']);
            $data['header_img'] = $this->userInfo('header_img',$data['user_id']);
            $data['level']      = $this->userExtra('level',$data['user_id']);
            $data['sign']      = $this->userInfo('sign',$data['user_id']);

        }else{
            api_return(0,'非法参数');
        }

        $data['user_id'] = hashid($data['user_id']);
        $data['to_user'] = hashid($data['to_user']);
        $data['self']    = hashid($this->user_id);
        $data['status_text'] = $data->status_text;

        return $data;
    }

    /**
     * 取消订单 退款
     * @param array $data
     * @param int $status
     * @return bool|string
     * @throws Exception
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    protected  function orderRefund( $data, $status = 5)
    {
        $array = [1,2,6,8];

        if (!in_array($data['status'],$array)){
            return '订单状态不允许退款';
        }

        Db::name('users')->where('user_id',$data['user_id'])->setInc('money',$data['price']);

        money_detail(1,$data['user_id'],'订单退款',$data['price'],'退款');

        Db::name('order')->where('order_id',$data['order_id'])->update(['status'=>$status]);

        return true;
    }

    /**
     * 订单取消
     * type=》1 接受邀约 type=》2 拒绝邀约 type=》3 完成订单
     * 消息推送
     */
    public function orderStatus()
    {
        $id = input('post.id');
        $type = input('post.type');

        if (!is_numeric($id)) api_return(0,'参数错误');
        $data = Order::where('order_id',$id)->find();
        if(!$data) api_return(0,'没有该订单');

        switch ($type)
        {
            case 1:
                if($data['status']!=1) api_return(0,'该订单当前状态不能操作');
                $result = $data->update(['status' => 2],['order_id' => $id]);
                Db::name('user_extend')->where('user_id',$data['to_user'])->setInc('order_num');
                
                break;
            case 2: //退款
                if($data['status']!=1) api_return(0,'该订单当前状态不能操作');

                $result = $this->orderRefund($data);

                break;
            case 3: //完成订单支付陪陪钻石
                if($data['status']!=2) api_return(0,'该订单当前状态不能操作');
                //邀约抽成比例
                $invite = self::extend('invite_ratio')??1;

                $ratio = $invite/100;

                //抽成后订单金额
                $money = bcsub($data['price'],bcmul($data['price'],$ratio,2),2);
                Db::name('users')->where('user_id',$data['to_user'])->setInc('cash',$money);
                money_detail(1,$data['to_user'],'完成订单',$money,'解锁',4,$id);
                $result = $data->update(['status' => 3],['order_id'=> $id]);

                break;
            default:
                api_return(0,'没有该操作！');
                break;
        }
        if ($result)
            api_return(1,'操作成功');
        api_return(0,$result);
    }

    /**
     * 订单评价
     */
    public function orderEvaluate()
    {
        $data = request()->only(['id','score','content'],'post');

        $map['order_id'] = $data['id'];
        $map['user_id']  = $this->user_id;
        $map['status']   = 3;

        $model = new Order();

        $order = $model->where($map)->find();
        if (!$order){
            api_return(0,'订单查询错误');
        }

        $where['apply_id'] = $order['apply_id'];
        $where['user_id']  = $order['to_user'];

        $apply = Db::name('skill_apply')->where($where)->field('score,score_num,apply_id')->find();
        $score_num = $apply['score_num']+1;
        $score = bcdiv(bcmul($apply['score'],$apply['score_num'],2)+$order['score'],$score_num,1);

        $change['score'] = $score;
        $change['score_num'] = $score_num;
        $change['update_time'] = time();

        Db::startTrans();
        try{

            //订单表修改
            $data['status'] = 4;
            $result = $order->validate('order.evaluate')->allowField(true)->save($data);
            if ($result === false){
                api_return(0,$order->getError());
            }

            //修改用户技能统计数据
            Db::name('skill_apply')->where('apply_id', $apply['apply_id'])->update($change);
            Db::name('user_extend')->where('user_id', $order['to_user'])->setInc('order_num');

            Db::commit();
        }catch (Exception $e){
            Db::rollback();
            api_return(0,$e->getMessage());
        }

        api_return(1,'评价成功');
    }

    /**
     * 订单确认
     */
    public function confirm()
    {
        $id = input('post.id');

        if (!isInt($id)) api_return(0,'参数错误');

        $model = new Order();

        $map['status']   = 1;
        $map['to_user']  = $this->user_id;
        $map['order_id'] = $id;

        $data = $model->where($map)->find();

        if (!$data) api_return(0,'订单查询错误');

        $result = $data->save(['status'=>2]);

        if ($result){
            $title = '和 '.$this->userInfo('nick_name',$data['user_id'].' '.getSkillName($data['skill_id']).' 确认');
            money_detail(1,$this->user_id,$title,$data['price'],'锁定');
            api_return(1,'订单确认成功');

        }

        api_return(0,$data->getError());

    }

    /**
     * 订单开始
     */
    public function start()
    {
        $id = input('post.id');
        if (!isInt($id)) api_return(0,'参数错误');
        $model = new Order();
        $map['status']   = 2;
        $map['user_id']  = $this->user_id;
        $map['order_id'] = $id;
        $data = $model->where($map)->find();
        if (!$data) api_return(0,'订单查询错误');
        $result = $data->save(['status'=>3]);
        if ($result){
            api_return(1,'订单开始成功');
        }
        api_return(0,$data->getError());
    }

    /**
     * 订单完成
     */
    public function finish()
    {
        $id = input('post.id');
        if (!isInt($id)) api_return(0,'参数错误');
        $map['status']   = 3;
        $map['user_id']  = $this->user_id;
        $map['order_id'] = $id;
        $order = Db::name('order')->where($map)->find();
        if (!$order) api_return(0, '订单查询错误');
        $result = self::complete($order);
        if ($result === true){
            api_return(1,'订单完成');
        }
        api_return(0,$result);
    }

    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 订单退款申请
     */
    public function refundApply()
    {

        $id     = input('post.id');
        $reason = input('post.reason');

        if (!isInt($id)) api_return(0,'参数错误');

        if (empty($reason)) api_return(0,'退款原因必须填写');

        $model = new Order();

        $map['status']   = 3;
        $map['user_id']  = $this->user_id;
        $map['order_id'] = $id;

        $data = $model->where($map)->find();
        if (!$data) api_return(0,'订单查询错误');

        $result = $data->save(['status'=>7,'reason'=>$reason]);

        if ($result){

            api_return(1,'退款申请成功');

        }

        api_return(0,$data->getError());

    }

    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 订单退款申请审核
     */
    public function check()
    {
        $id     = input('post.id');

        $status = input('post.status');

        if ($status != 11 && $status != 8) api_return(0,'类型错误');

        if (!isInt($id)) api_return(0,'参数错误');

        $model = new Order();

        $map['status']   = 7;
        $map['to_user']  = $this->user_id;
        $map['order_id'] = $id;

        $data = $model->where($map)->find();
        if (!$data) api_return(0,'订单查询错误');



        if ($status == 11){ //退款申请通过
            $result = self::refund($id,$status);
            if ($result !== true){
                api_return(0,$result);
            }else{
                api_return(1,'退款成功');
            }
        }else{
            $result = $data->save(['status'=>$status]);
            if ($result){
                api_return(1,'退款驳回成功');
            }
            api_return(0,$data->getError());
        }
    }

    public function protest(int $id)
    {
        $map['order_id'] = $id;
        $map['user_id']  = $this->user_id;
        $map['status']   = 8;

        $model = new Order();

        $data = $model->where($map)->find();
        if (!$data){
            api_return(0,'订单查询错误');
        }

        $result = $data->save(['status'=>9]);

        if ($result !== false){
            api_return(1,'申请成功,请与客服联系或耐心等待管理员审核');
        }
        api_return(0,$data->getError());

    }


    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 订单评价页面
     */
    public function evaluateView(int $id)
    {

        $map['a.order_id'] = $id;
        $map['a.user_id']  = $this->user_id;
        $map['a.status']   = 4;

        $model = new Order();

        $data = $model->evaluateInfo($map);
        if (!$data){
            api_return(0,'订单查询错误');
        }

        $data['noble_id'] = self::checkNoble($data);

        $data['order_time'] = formatTime($data['order_time']);

        $data['tags'] = getSkillTags($data['tag'],true);

        api_return(1,'获取成功',$data);

    }

    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 闪电邀约
     */
    public function fastOrder()
    {

        $this->ApiLimit(5,$this->user_id);

        $data = request()->only(['skill_id','order_time','grade','tag','type','room_id','form_id','remark','num','sex'],'post');

        $model = new apply();

        $map['e.invite'] = 1;
        $map['e.online_status'] = 1;

        if (isInt($data['skill_id'])){
            $map['a.skill_id'] = $data['skill_id'];
        }else{
            api_return(0,'技能id错误');
        }

        if (!is_numeric($data['room_id'])){
            api_return(0,'房间id错误');
        }


        //判断是否为点单房间里的点单消息
        if ($data['type'] == 'order'){
            if (!is_numeric($data['room_id'])) {
                api_return(0, '点单房间邀约需传房间id');
            }

            $map1['room_id'] = $data['room_id'];
            $map1['status']  = 0;

            $record = OrderRecord::where($map1)->find();
            if ($record){
                api_return(0,'派单还未结束!');
            }

//            $map['e.room_id'] = ['neq',$data['room_id']];


        }else{
            api_return(0,'参数错误');
        }

        if (is_numeric($data['sex'])){
            $map['u.sex'] = $data['sex'];
        }

//        $map['j_push_id'] = ['neq',null];

        $rows = $model->getFast($map);
        $data['user_id'] = $this->user_id;
        if ($rows){

            $item['user_id'] = $this->user_id;
            $item['status']  = 0;
            $item['room_id'] = $data['room_id'];
            $item['create_time'] = time();
            //保存派单信息
            OrderRecord::insert($item);

            $response['skill_name']  = $rows[0]['skill_name'];
            $response['skill_img']   = $rows[0]['skill_img'];
            $response['create_time'] = time();
            $response['room_id']     = $data['room_id'];
            $response['tips_id']     = $item['create_time'];
            $response['type']        = 1;
            $response['remark']      = $data['remark'];
            $response['remark']      = $data['remark'];
            $extras['type'] = 1;
            $extras['data'] = $response;

            foreach ($rows as $k => $v){

                if ($v['j_push_id']){
                    $str =  sprintf('抢单啦！来自派单厅的[%s]订单正在呼唤你，快到订单中心抢单吧！',$response['skill_name']);
                    $data = j_push($str,$v['j_push_id'],['extras'=>$extras]);
                    self::sendUsrMsg('system',hashid($v['user_id']),$str);
                }
            }
            cache('fastOrder_'.hashid($this->user_id),$data);
            api_return(1,'派单成功');

        }else{
            api_return(0,'当前无合适用户在线');
        }

    }


    //闪电邀约用户列表缓存前缀
    protected $fastUserListPrefix = 'fastOrderUsers_';

    //闪电邀约条件缓存前缀
    protected $fastPrefix = 'fastOrder_';

    /**
     * 结束闪电邀约
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     */
    public function endOrder()
    {
        $group_id = input('group_id');
        cache($this->fastPrefix.$group_id,null);
        cache($this->fastUserListPrefix.$group_id,null);
        api_return(1,'结束成功');
    }







    /**
     * 接收派单
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     */
    public function acceptOrder()
    {
        $data = input('post.');

        $map['room_id'] = $data['room_id'];
        $map['status']  = 0;

        $id = OrderRecord::where($map)->value('create_time');

        if (empty($id) || $id != $data['id']){
            api_return(0,'派单已结束');
        }
        api_return(1,'允许进入');

    }

    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 接受闪电邀约
     */
    public function accept()
    {
        $group_id = input('post.group_id');

        $data = cache('fastOrder_'.$group_id);

        if (!$data){
            api_return(0,'已结束邀请');
        }

        api_return(1,'接受邀请成功,连接socket');
    }


    /**
     * Created by xiaosong
     * E-mail:4155433@gmail.com
     * 闪电邀约取消
     */
    public function cancel()
    {
        $hash = hashid($this->user_id);

        Events::groupResponse(400,$hash,'闪电邀约取消');

        Gateway::ungroup($hash);

        api_return(1,'取消成功');
    }

    /**
     * 推荐陪陪
     */
    public function recommendUsers()
    {
        $map = [];
        $rows = apply::recommendUsers($map);
        $map['f.price'] = ['neq',0];
        api_return(1,'获取成功', $rows);
    }
}